function [ Version, NumOfCase, LOES, NumOfEntities, NumOfFault, LOFS, Result, Coverage ] = dataHandle( filename, version )
% Handling the coverage/data file
% Parameter:
%     filename:   the name of program, example: 'tcas';
%     version:    version of program, example: '1';
% Output:
%     Version:    name and version of program;
%     NumOfCase:  the total number of test cases;
%     LOES:       the locations of executable entities;
%     NumOfEntities:  the number of executable entities;
%     NumOfFault: the number of faults;
%     LOFS:       the locations of faults;
%     Result:     the vector of results;
%     Coverage:   the matrix of coverage information;

    %Open file
    name = ['./data/',filename,'/v',version,'/output',version,'.txt'];
    fid = fopen(name);

    %Version name and number
    temp = fgetl(fid);
    if strfind(temp, '#Ver_#')
        Version = strtrim(temp(8:end));
    end

        %Number of test cases
        temp = fgetl(fid);
        if strfind(temp, '#NOTS#')
            NumOfCase = eval(temp(8:end));
        end

        %Locations of executable statements
        temp = fgetl(fid);
        if strfind(temp, '#LOES#')
            temp = temp(8:end);
            LOES = str2num(temp)';
        end

        %Number of executable statements
        temp = fgetl(fid);
        if strfind(temp, '#NOES#')
            NumOfEntities = eval(temp(8:end));
        end

        %Number of faults
        temp = fgetl(fid);
        if strfind(temp, '#NOF_#')
            NumOfFault = eval(temp(8:end));
        end

        %Locations of faults
        temp = fgetl(fid);
        if strfind(temp, '#LOFS#')
            temp = temp(8:end);
            LOFS = str2num(temp)';
        end

        %Convert LOFS to newLOFS
        newLOFS = [];
        for n = 1:length(LOFS)
            newLOFS = [newLOFS;find(LOES==LOFS(n))];
        end

        %Coverage and result
        Result = zeros(NumOfCase,1);
        Coverage = zeros(NumOfCase,NumOfEntities);
        n = 1;
    while ~feof(fid)
        temp = fgetl(fid);
        Result(n) = eval(temp(14));
        temp = temp(16:end);
        CoverageRow = str2num(temp);
        Coverage(n,:) = CoverageRow;
        n = n+1;
    end

    fclose(fid);
end